package com.byzk.invoice.xml.Doc_0;

import com.byzk.invoice.util.DocumentUtil;
import org.dom4j.*;

import java.io.File;

/**
 * 创建PublicRes.xml.
 *
 * @author 康鹏 2020-05-20
 */
public class PublicRes {

    /**
     * 创建Doc_0/PublicRes.xml.
     * @param publicResXmlPath PublicRes.xml存放路径
     * @throws Exception Exception
     */
    public static void createPublicResXml(String publicResXmlPath) throws Exception {

        Namespace namespace = new Namespace("ofd", "http://www.ofdspec.org/2016");
        //创建外层<ofd:Res />
        Element rootElt = DocumentHelper.createElement(new QName("Res", namespace));
        rootElt.addAttribute("BaseLoc", "Res");
        //创建<ofd:ColorSpaces />
        Element colorSpacesElt = rootElt.addElement("ofd:ColorSpaces");
        //创建<ofd:ColorSpace />
        Element colorSpaceElt = colorSpacesElt.addElement("ofd:ColorSpace");
        colorSpaceElt.addAttribute("ID", "7");
        colorSpaceElt.addAttribute("Type", "RGB");
        colorSpaceElt.addAttribute("BitPerComponent", "8");
        //创建<ofd:Fonts />
        Element fontsElt = rootElt.addElement("ofd:Fonts");
        //创建<ofd:Font />
        Element fontElt1 = fontsElt.addElement("ofd:Font");
        fontElt1.addAttribute("ID", "28");
        fontElt1.addAttribute("FontName", "楷体");
        fontElt1.addAttribute("FamilyName", "楷体");
        Element fontElt2 = fontsElt.addElement("ofd:Font");
        fontElt2.addAttribute("ID", "85");
        fontElt2.addAttribute("FontName", "宋体");
        fontElt2.addAttribute("FamilyName", "宋体");
        Element fontElt3 = fontsElt.addElement("ofd:Font");
        fontElt3.addAttribute("ID", "88");
        fontElt3.addAttribute("FontName", "Courier New");
        fontElt3.addAttribute("FamilyName", "Courier New");

        Document document = DocumentHelper.createDocument(rootElt);
        DocumentUtil.writer(document, publicResXmlPath + File.separator + "Doc_0"
                + File.separator + "PublicRes.xml", true);
    }

}
